/*
 * @Author: szx
 * @Date: 2022-03-04 12:39:03
 * @LastEditTime: 2022-03-04 13:38:30
 * @Description:
 * @FilePath: \leetcode\2100-2199\2104\2104.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var subArrayRanges = function (nums) {
    let res = 0;
    for (let i = 0; i < nums.length; i++) {
        let minVal = Number.MAX_VALUE,
            maxVal = -Number.MAX_VALUE;
        for (let j = i; j < nums.length; j++) {
            minVal = Math.min(minVal, nums[j]);
            maxVal = Math.max(maxVal, nums[j]);
            res += maxVal - minVal;
        }
    }
    return res;
};


console.log(subArrayRanges([1, 3, 2]));
console.log(subArrayRanges([1, 3, 3]));
console.log(subArrayRanges([4, -2, -3, 4, 1]));
